<!DOCTYPE HTML>
<html  xmlns:th="http://www.thymeleaf.org">
<head th:include="_meta :: header">
<title>编辑管理员 - 管理员管理 </title>
</head>
<body>
<div class="layui-fluid">
	<div class="layui-row">
		<form class="layui-form" id="form-admin-add" action="#" th:action="@{/user/edit-user}" th:object="${user}">
			<input type="hidden" name="save" value="true"/>
			<input type="hidden" name="id" value="" th:field="*{id}"/>

			<div class="layui-form-item">
				<label for="username" class="layui-form-label">
					<span class="x-red">*</span>管理员
				</label>
				<div class="layui-input-inline">
					<input type="text" id="username" name="username"  readonly="readonly" required="" lay-verify="required"
						   autocomplete="off" class="layui-input" th:field="*{username}">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">
					<span class="x-red">*</span>性别
				</label>
				<div class="layui-input-inline">
					<input type="radio" id="sex-1" name="sexType" value="1" th:field="*{sexType}" title="男"  checked="checked">
					<input type="radio"  id="sex-0" name="sexType" value="0" th:field="*{sexType}" title="女">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">
					<span class="x-red">*</span>是否启用
				</label>
				<div class="layui-input-inline">
					<input type="radio" id="qd" name="available" value="1" th:field="*{available}" title="启用"  checked="checked">
					<input type="radio"  id="nqd" name="available" value="0" th:field="*{available}" title="不启用">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
					手机
				</label>
				<div class="layui-input-inline">
					<input type="te xt" id="tel" name="tel"  th:field="*{tel}"
						   autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
					邮箱
				</label>
				<div class="layui-input-inline">
					<input type="text" id="email" name="email" r th:field="*{email}"
						   autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
					角色
				</label>
				<div class="layui-input-inline">
					<span  th:each="role : ${roleList}" >
				<span th:each="userrole:*{roles}" >
						<input type="radio" th:value="${role.id}" value="" name="userRoles" th:title="${role.name}" th:checked="${userrole.id eq role.id}">
				</span>
			</span>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
				</label>
				<button  class="layui-btn" id="subbtn" type="submit">
					保存
				</button>
			</div>
		</form>
	</div>
</div>

<!--_footer 作为公共模版分离出去--> 
<div th:replace="_footer :: footerjs">
</div>
 <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/jquery.validate.js}" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/validate-methods.js}" src="lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/messages_zh.js}"  src="lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function(){
	layui.use(['form', 'layer'],function() {
		$ = layui.jquery;
		var form = layui.form,
		layer = layui.layer;
	});
	
	$("#form-admin-add").validate({
		rules:{
			username:{
				required:true,
				minlength:4,
				maxlength:16
			},
			sexType:{
				required:true,
			},
			tel:{
				isPhone:true,
			},
			email:{
				email:true,
			},
		},
		onkeyup:false,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				type: 'post',
				url: "/user/edit-user" ,
				success: function(data){
					if(data == "1"){
						layer.msg('编辑成功!',{icon:1,time:1000},function(){
							var index = parent.layer.getFrameIndex(window.name);
							parent.location.reload();
							parent.layer.close(index); 
						});
					}else{
						layer.msg('编辑失败!',{icon:1,time:1000});
					}
				},
                error: function(XmlHttpRequest, textStatus, errorThrown){
					layer.msg('error!',{icon:1,time:1000});
				}
			});
		
		}
	});
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>